package hy.service;

import hy.beans.Item;
import hy.beans.Order;
import hy.dao.OrderDao;
import hy.dao.StoreDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MyTask {
    @Autowired
    private OrderDao orderDao;
    @Autowired
    private StoreDao storeDao;

    //@Async
    void order(Order o){
        orderDao.saveOrder(o);
        for(Item i:o.getItems()){
            orderDao.saveItems(i);
        }
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("order结束");
    }
    //@Async
    void item(Order o){
        for(Item i:o.getItems()){
            storeDao.reduceNum(i);
        }
        System.out.println("item结束");
    }
}
